package com.icss.train_sys_back.controller.admin.statistics_manage;

import com.icss.train_sys_back.entity.ResponseResult;
import com.icss.train_sys_back.entity.statistics_manage.PopularStationEntity;
import com.icss.train_sys_back.entity.statistics_manage.PopularTrainsEntity;
import com.icss.train_sys_back.entity.statistics_manage.SalesTrendEntity;
import com.icss.train_sys_back.entity.statistics_manage.TicketStatisticsEntity;
import com.icss.train_sys_back.service.statistics_manage.TicketStatisticsManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 小泽
 * @createTime 2025/10/9 9:07
 */
@RestController
@RequestMapping("/admin/statistics/ticket")
@Slf4j
public class TicketStatisticsManageController {
    @Autowired
    private TicketStatisticsManageService ticketStatisticsManageService;

    //票务统计分析
    @GetMapping("/summary")
    public ResponseResult ticketStatistics(@RequestParam(required = false) String dateType,
                                           @RequestParam(required = false) String trainType,
                                           @RequestParam(required = false) Integer station,
                                           @RequestParam(required = false) String startDate,
                                           @RequestParam(required = false) String endDate) {
        log.info("票务统计分析 dateType = {} ,  startDate = {} , endDate = {} , trainType = {} , station = {} ",
                dateType, startDate, endDate, trainType, station);

        TicketStatisticsEntity ticketStatistics = ticketStatisticsManageService.ticketStatistics(dateType, trainType, station, startDate, endDate);
        return ResponseResult.success(ticketStatistics);
    }

    //当月销售额统计
    @GetMapping("/salesTrend")
    public ResponseResult salesTrend() {
        log.info("当月销售额统计");
        SalesTrendEntity salesTrend = ticketStatisticsManageService.salesTrend();
        return ResponseResult.success(salesTrend);
    }

    //热门车次统计
    @GetMapping("/popularTrains")
    public ResponseResult popularTrains(@RequestParam(required = false) String dateType,
                                        @RequestParam(required = false) String trainType,
                                        @RequestParam(required = false) Integer station,
                                        @RequestParam(required = false) String startDate,
                                        @RequestParam(required = false) String endDate) {
        log.info("热门车次统计 dateType = {} ,  startDate = {} , endDate = {} , trainType = {} , station = {} ",
                dateType, startDate, endDate, trainType, station);

        //时间范围查询
        List<PopularTrainsEntity> popularTrains = ticketStatisticsManageService.popularTrains(startDate, endDate);
        return ResponseResult.success(popularTrains);
    }

    //热门站点
    @GetMapping("/popularStations")
    public ResponseResult popularStations(@RequestParam(required = false) String dateType,
                                          @RequestParam(required = false) String trainType,
                                          @RequestParam(required = false) Integer station,
                                          @RequestParam(required = false) String startDate,
                                          @RequestParam(required = false) String endDate) {
        log.info("热门站点统计 dateType = {} ,  startDate = {} , endDate = {} , trainType = {} , station = {} ",
                dateType, startDate, endDate, trainType, station);

        //时间范围查询
        List<PopularStationEntity> popularStationEntities = ticketStatisticsManageService.popularStations(startDate, endDate);
        return ResponseResult.success(popularStationEntities);
    }
}
